<?xml version="1.0" encoding="UTF-8"?>
<%@page import="javax.script.ScriptEngine"%>
<%@page import="javax.script.ScriptEngineManager"%>
<%@page import="com.hente.common.BaiduAPIConverter"%>
<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	String realPath = request.getRealPath("/");

	if("query".equals(request.getParameter("type"))){
		
		String lng = request.getParameter("lng");
		String lat = request.getParameter("lat");
		if(lng != null && !"".equals(lng) && lat != null && !"".equals(lat)){
			String[] ss = BaiduAPIConverter.getInstance().convertLL2MC(Double.parseDouble(lng),Double.parseDouble(lat),realPath);
			String url = "http://api.map.baidu.com/?qt=rgc&x=" + ss[0]+ "&y=" + ss[1] + "&dis_poi=100&poi_num=10&res=api";
			
			
			ScriptEngineManager sem = new ScriptEngineManager(); 
			ScriptEngine se  = sem.getEngineByName("javascript");  
			se.eval("var result = " + BaiduAPIConverter.getInstance().postUrl(url));
			String infoMessage = (String)se.eval("result.content.address + ''");
			if(infoMessage != null && !"".equals(infoMessage)){
				request.setAttribute("infoMessage",infoMessage);
			}else {
				request.setAttribute("infoMessage","没有符合该坐标的地址");
			}
			
		}else {
			request.setAttribute("infoMessage","输入的格式坐标信息不正确");
		}
		
	}
%>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="http://a.xnimg.cn/wap/apple_icon_.png" rel="apple-touch-icon-precomposed" />
<link rel="stylesheet" href="/wap/css/i.css" type="text/css"/>
</head>

<body>
<div class="sectitle">位置查询</div>
<div class="sec nb gray"></div>
<div class="sec">
<form action="index.jsp?type=query" method="post">
<p>经度:<br /><input type="text" name="lng" value="${param.lng}" /><br />
纬度:<br /><input type="text" name="lat" value="${param.lat}" /></p><p>
<input type="submit" name="login" value="查询" class="button" />&nbsp;
</p>
</form>
</div>
<div id="footer">
      	<c:if test="${not empty infoMessage}">
			${infoMessage }<br>
	    </c:if>
</div>
</body>
</html>